document.addEventListener("plusready", function() {
	var _BARCODE = 'blecontroler',
		B = window.plus.bridge;
	var blecontroler = {
		//test
		getTest: function(isSucess, successCallback, errorCallback) {
			var success = typeof successCallback !== 'function' ? null : function(args) {
					successCallback(args);
				},
				fail = typeof errorCallback !== 'function' ? null : function(code) {
					errorCallback(code);
				};
			callbackID = B.callbackId(success, fail);
			return B.exec(_BARCODE, "getTest", [callbackID, isSucess]);
		},
		//初始化蓝牙模块
		init: function() {
			return B.execSync(_BARCODE, "start");
		},
		//销毁蓝牙连接
		destory: function() {
			return B.execSync(_BARCODE, "destory");
		},
		//扫描ble蓝牙设备
		scan: function(bleName, successCallback, errorCallback) {
			var success = typeof successCallback !== 'function' ? null : function(args) {
					successCallback(args);
				},
				fail = typeof errorCallback !== 'function' ? null : function(code) {
					errorCallback(code);
				};
			callbackID = B.callbackId(success, fail);

			return B.exec(_BARCODE, "getBleList", [callbackID, bleName]);
		},
		//连接ble蓝牙设备
		connectBle: function(mac, successCallback, errorCallback) {
			var success = typeof successCallback !== 'function' ? null : function(args) {
					successCallback(args);
				},
				fail = typeof errorCallback !== 'function' ? null : function(code) {
					errorCallback(code);
				};
			callbackID = B.callbackId(success, fail);

			return B.exec(_BARCODE, "connectBle", [callbackID, mac]);
		},
		//断开连接ble设备
		disconnectBle: function(mac) {
			return B.execSync(_BARCODE, "disconnectBle", [mac]);
		},
		//发送指令并且接收返回
		writeData: function(hex, successCallback, errorCallback) {
			var success = typeof successCallback !== 'function' ? null : function(args) {
					successCallback(args);
				},
				fail = typeof errorCallback !== 'function' ? null : function(code) {
					errorCallback(code);
				};
			callbackID = B.callbackId(success, fail);

			return B.exec(_BARCODE, "writeData", [callbackID, hex]);
		},

		//文件解析成16进制
		getHexFromFile: function(fullPath, successCallback, errorCallback) {
            var success = typeof successCallback !== 'function' ? null : function(args) {
                 successCallback(args);
            },
           fail = typeof errorCallback !== 'function' ? null : function(code) {
                 errorCallback(code);
           };
           callbackID = B.callbackId(success, fail);
            return B.exec(_BARCODE, "getHexFromFile", [callbackID, fullPath]);
         },

		//暂时不用
		setNotifyListener: function(successCallback, errorCallback) {
			var success = typeof successCallback !== 'function' ? null : function(args) {
					successCallback(args);
				},
				fail = typeof errorCallback !== 'function' ? null : function(code) {
					errorCallback(code);
				};
			callbackID = B.callbackId(success, fail);

			return B.exec(_BARCODE, "setNotifyListener", [callbackID]);
		},

	};
	window.plus.blecontroler = blecontroler;
}, true);